import numpy as np
from environment_pool import *
from FDTDGrid import call_FDTDgrid_filter_vis,call_Tet2FDTDgrid,set_threads,call_bin2FDTDgridSize,call_bin2FDTDgrid
from FDTDGrid import call_Tet2FDTDgrid_feko
def bin2FDTDGrid(binName):
    nsize = np.zeros((3),dtype=np.int32)
    call_bin2FDTDgridSize(binName,nsize)
    nx = nsize[0]-1
    ny = nsize[1]-1
    nz = nsize[2]-1
    icoat = np.zeros((nx,ny,nz),dtype=np.int32)
    call_bin2FDTDgrid(binName,icoat.ravel())
    return icoat
print('defining the problem space parameters')
# maximum number of time steps to run FDTD simulation
number_of_time_steps = number_of_time_steps_pool #  326 #1079 

# A factor that determines duration of a time step
# wrt CFL limit
courant_factor = courant_factor_pool

# A factor determining the accuracy limit of FDTD results
number_of_cells_per_wavelength = number_of_cells_per_wavelength_pool    

# Dimensions of a unit cell in x, y, and z directions (meters)
dx = dx_pool
dy = dy_pool
dz = dz_pool
set_threads(16)
dsize = np.array([ dx,dy,dz],dtype=np.float32 )
if(mesh_type_pool==1):
    dsize = np.array([ dx*1000,dy*1000,dz*1000],dtype=np.float32 )
    #call_Tet2FDTDgrid_feko(mesh_input_pool, fdtd_mesh_pool,dsize)
    call_Tet2FDTDgrid(mesh_input_pool, fdtd_mesh_pool,dsize)
if(mesh_type_pool>0):
    #TODO:1
    icoat_pool = bin2FDTDGrid(fdtd_mesh_pool)

# ==<boundary conditions>========
# Here we define the boundary conditions parameters 
# 'pec' : perfect electric conductor
# 'cpml' : conlvolutional PML
# if cpml_number_of_cells is less than zero
# CPML extends inside of the domain rather than outwards
boundary = boundary_pool

# ===<material types>============
# Here we define and initialize the arrays of material types
# eps_r   : relative permittivity
# mu_r    : relative permeability
# sigma_e : electric conductivity
# sigma_m : magnetic conductivity
material_types = material_types_pool
for material_type in material_types:
    material_type["deps"] = material_type["eps_s"]-material_type["eps_r"]


# 定义激励源
# 激励源类型
waveform_type = waveform_type_pool #1代表正弦波，2代表高斯脉冲
# 正弦波
f_sinwave = f_sinwave_pool
# 高斯脉冲
setbandwidth = setbandwidth_pool# 带宽
f_center = f_center_pool# 中心频率
src_pos_x = src_pos_x_pool
src_pos_y = src_pos_y_pool
src_pos_z = src_pos_z_pool
src_compoinent = src_compoinent_pool

time_user = time_user_pool